import {BrowserWindow} from "electron";
import {IsUseSysTitle} from "../config/const";
import {otherWindowConfig} from "../config/windowsConfig";
import {printURL} from "../config/staticPath";
import {openDevTools} from "../hook/devToolHook";

let win: BrowserWindow;

export function openPrintDemoWindow() {
	if (win) {
		win.show();
		return;
	}
	win = new BrowserWindow({
		titleBarStyle: IsUseSysTitle ? "default" : "hidden",
		...Object.assign(otherWindowConfig, {}),
	});
	// 开发模式下自动开启devtools
	if (process.env.NODE_ENV === "development") {
		openDevTools(win);
	}
	win.loadURL(printURL);
	win.on("ready-to-show", () => {
		win.show();
	});
	win.on("closed", () => {
		win = null;
	});
}
